package com.bagus.mediapipefacedetection.listener;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;

import java.io.ByteArrayOutputStream;

public class ResultEntity {
    private Bitmap imageCutDown;
    private Rect faceRect;
    private byte[] orgData;
    private String orgUri;
    private String cutUri;

    public ResultEntity(Bitmap imageCutDown, Rect faceRect, byte[] orgData) {
        this.imageCutDown = imageCutDown;
        this.faceRect = faceRect;
        this.orgData = orgData;
    }

    public ResultEntity(Bitmap imageCutDown, Rect faceRect, byte[] orgData, String orgUri) {
        this.imageCutDown = imageCutDown;
        this.faceRect = faceRect;
        this.orgData = orgData;
        this.orgUri = orgUri;
    }

    public ResultEntity(String orgUri, String cutUri) {
        this.orgUri = orgUri;
        this.cutUri = cutUri;
    }

    public String getCutUri() {
        return cutUri;
    }

    public void setCutUri(String cutUri) {
        this.cutUri = cutUri;
    }

    public String getOrgUri() {
        return orgUri;
    }

    public void setOrgUri(String orgUri) {
        this.orgUri = orgUri;
    }

    public Bitmap getImageCutDown() {
        return imageCutDown;
    }

    public Rect getFaceRect() {
        return faceRect;
    }

    public byte[] getOrgData() {
        return orgData;
    }

    public static Bitmap convertStringToIcon(byte[] bitmapArray) {
        if(bitmapArray == null){
            return null;
        }
        YuvImage yuvimage=new YuvImage(bitmapArray, ImageFormat.NV21, 20,20, null);//20、20分别是图的宽度与高度
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        yuvimage.compressToJpeg(new Rect(0, 0,20, 20), 80, baos);//80--JPG图片的质量[0-100],100最高
        byte[] jdata = baos.toByteArray();

        // OutputStream out;
        Bitmap bitmap = null;
        try {
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inDither = true;
            opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
            bitmap = BitmapFactory.decodeByteArray(jdata, 0, jdata.length, opt);
            // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
//            show_image.setImageBitmap(bitmap);
            return bitmap;
        } catch (Exception e) {
            return null;
        }
    }
}
